.\" Copyright (c) 2006,2008,2020 Joseph Koshy.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" This software is provided by Joseph Koshy ``as is'' and
.\" any express or implied warranties, including, but not limited to, the
.\" implied warranties of merchantability and fitness for a particular purpose
.\" are disclaimed.  in no event shall Joseph Koshy be liable
.\" for any direct, indirect, incidental, special, exemplary, or consequential
.\" damages (including, but not limited to, procurement of substitute goods
.\" or services; loss of use, data, or profits; or business interruption)
.\" however caused and on any theory of liability, whether in contract, strict
.\" liability, or tort (including negligence or otherwise) arising in any way
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
.\" $Id: gelf_getsymshndx.3 3958 2022-03-12 14:31:32Z jkoshy $
.\"
.Dd September 26, 2020
.Dt GELF_GETSYMSHNDX 3
.Os
.Sh NAME
.Nm gelf_getsymshndx ,
.Nm gelf_update_symshndx
.Nd read and update symbol information using extended section indices
.Sh LIBRARY
.Lb libelf
.Sh SYNOPSIS
.In gelf.h
.Ft "GElf_Sym *"
.Fo gelf_getsymshndx
.Fa "Elf_Data *symdata"
.Fa "Elf_Data *xndxdata"
.Fa "int ndx"
.Fa "GElf_Sym *sym"
.Fa "Elf32_Word *xndxptr"
.Fc
.Ft int
.Fo gelf_update_symshndx
.Fa "Elf_Data *symdata"
.Fa "Elf_Data *xndxdata"
.Fa "int ndx"
.Fa "GElf_Sym *sym"
.Fa "Elf32_Word xndx"
.Fc
.Sh DESCRIPTION
These functions are analogous to
.Fn gelf_getsym
and
.Fn gelf_update_sym
respectively, but are capable of handling symbol tables using extended
section numbering.
.Pp
Argument
.Fa symdata
is an
.Vt Elf_Data
descriptor associated with a section of type
.Dv SHT_SYMTAB .
Argument
.Fa xndxdata
is an
.Vt Elf_Data
descriptor associated with a section of type
.Dv SHT_SYMTAB_SHNDX .
Argument
.Fa ndx
is the index of the symbol table entry being retrieved or updated.
Argument
.Fa sym
is a pointer to a class-independent
.Vt GElf_Sym
structure.
.Vt GElf_Sym
structures are described in detail in
.Xr gelf 3 .
.Pp
Function
.Fn gelf_getsymshndx
retrieves symbol information at index
.Fa ndx
from the data descriptor specified by argument
.Fa symdata
and stores it in class-independent form in argument
.Fa sym .
Additionally:
.Bl -bullet
.It
If the arguments
.Ad xndxdata
and
.Fa xndxptr
are both not
.Dv NULL ,
it retrieves the extended section index for the
symbol from the data buffer pointed to by the
argument
.Fa xndxdata
and stores it into the location pointed to by argument
.Fa xndxptr .
.It
Otherwise, if the argument
.Fa xndxptr
is not
.Dv NULL ,
a value of zero is stored into the location pointed to by
argument
.Fa xndxptr .
.El
.Pp
Function
.Fn gelf_update_symshndx
updates the underlying symbol table entry in the data
descriptor
.Fa symdata
with the information in argument
.Fa sym .
In addition it sets the extended section index in
data buffer
.Fa xndxdata
to the value of argument
.Fa xndx .
.Sh RETURN VALUES
Function
.Fn gelf_getsymshndx
returns the value of argument
.Fa sym
if successful, or
.Dv NULL
in case of an error.
.Pp
Function
.Fn gelf_update_symshndx
returns a non-zero value if successful, or zero in case of an error.
.Sh ERRORS
These functions may fail with the following errors:
.Bl -tag -width "[ELF_E_RESOURCE]"
.It Bq Er ELF_E_ARGUMENT
Arguments
.Fa symdata ,
.Fa xndxdata ,
.Fa xndxptr
or
.Fa sym
were
.Dv NULL .
.It Bq Er ELF_E_ARGUMENT
Argument
.Fa ndx
was less than zero, or too large for either of descriptors
.Fa symdata
or
.Fa xndxdata .
.It Bq Er ELF_E_ARGUMENT
Data descriptor
.Fa symdata
was not associated with a section of type
.Dv SHT_SYMTAB .
.It Bq Er ELF_E_ARGUMENT
Data descriptor
.Fa xndxdata
was not associated with a section of type
.Dv SHT_SYMTAB_SHNDX .
.It Bq Er ELF_E_ARGUMENT
Data descriptor
.Fa symdata
and
.Fa xndxdata
were associated with different ELF objects.
.It Bq Er ELF_E_VERSION
The
.Vt Elf_Data
descriptors denoted by arguments
.Fa symdata
and
.Fa xndxdata
are associated with an ELF object with an unsupported version.
.El
.Sh SEE ALSO
.Xr elf 3 ,
.Xr elf_getdata 3 ,
.Xr elf_getscn 3 ,
.Xr gelf 3 ,
.Xr gelf_getsym 3 ,
.Xr gelf_update_sym 3
